package org.innovasix.educational.javap.domain.constantpool;

import org.innovasix.educational.javap.domain.datatypes.cp_info;
import org.innovasix.educational.javap.domain.datatypes.u1;
import org.innovasix.educational.javap.domain.datatypes.u2;
import org.innovasix.educational.javap.domain.parser.ByteQueue;

/**
 * <p>
 * <b><i>From the JVM specification:</i></b><br/>
 * The CONSTANT_InterfaceMethodref_info structure is used to represent an interface method.
 * </p>
 * 
 * @see <a
 *      href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.1">4.4.1.
 *      The CONSTANT_Class_info Structure</a>
 * 
 * @author sven.mentl@gmail.com
 * 
 */
public class CONSTANT_Methodref_info extends cp_info {

	public CONSTANT_Methodref_info(ByteQueue byteQueue) {
		class_index = byteQueue.pollTwoBytes(CONSTANT_Methodref_info.class.getCanonicalName());
		name_and_type_index = byteQueue.pollTwoBytes(CONSTANT_Methodref_info.class.getCanonicalName());
	}

	/**
	 * <p>
	 * <b><i>From the JVM specification:</i></b><br/>
	 * The tag item has the value CONSTANT_Methodref(10).
	 * </p>
	 */
	final u1 tag = new u1(ConstantPoolTags.CONSTANT_Methodref.decimalValue());

	/**
	 * <p>
	 * <b><i>From the JVM specification:</i></b><br/>
	 * The value of the class_index item must be a valid index into the
	 * constant_pool table. The constant_pool entry at that index must be a
	 * CONSTANT_Class_info structure representing an interface type that
	 * has this method as a member.
	 * </p>
	 */
	u2 class_index;

	/**
	 * <p>
	 * <b><i>From the JVM specification:</i></b><br/>
	 * The value of the name_and_type_index item must be a valid index into the
	 * constant_pool table. The constant_pool entry at that index must be a
	 * CONSTANT_NameAndType_info structure. This constant_pool entry indicates the name and descriptor of the method.
	 * The descriptor is a method descriptor (which is a sequence of characters e.g.: (IDLjava/lang/Thread;)Ljava/lang/Object;
	 * </p>
	 */
	u2 name_and_type_index;
	
	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append("CONSTANT_Methodref_info [");
		sb.append("class_index: #");
		sb.append(class_index);
		sb.append(" name_and_type_index: #");
		sb.append(name_and_type_index);
		sb.append("]");
		return sb.toString();
	}
}
